import requests
import os
import time


filename = input('filename:')
# uploadUrl = 'http://66.42.98.112:5000/upload'
# uploadUrl = 'http://localhost:5000/upload'
uploadUrl = 'http://149.248.20.132:5000/upload'

headers = {
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'}

# 上传的数据参数
payload = {'DEFAULT_SRC_LANGUAGE': 'en',
           'DEFAULT_DST_LANGUAGE': 'en', 'diglossia': '2'}


def uploadFile(filename, uploadUrl, payload,headers):
    # 上传文件到服务器
    file = {'file': open(filename, 'rb')}
    r = requests.post(uploadUrl, files=file, data=payload,headers=headers)
    fileRes = r.text  # 获取文件内容
    # basePath是最开始获取文件时的文件路径
    filename_srt = basePath+'.srt'
    print('filename_srt==>'+filename_srt)
    with open(filename_srt, 'w', encoding='utf-8') as f:  # 保存文件
        # with open(os.path.join(basepath, filename_srt),'w') as f: # 保存文件
        print('开始写数据啦~~')
        f.write(fileRes)
        print('写入成功~~')
        win.label_3.setPixmap(QPixmap(":/pic/over.jpg"))


uploadFile(filename, uploadUrl, payload,headers)
